package installer.comment;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

public class InstallComment {
	private static JdbcTemplate jdbcTemplate;

	@BeforeClass
	public static void before() {
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"config/context/applicationContext.xml");
		jdbcTemplate = (JdbcTemplate) ctx.getBean("jdbcTemplate");
	}

	@Test
	public void install() {
		try {
			String sql="";
			String contentsql= " (commentid bigint PRIMARY KEY  AUTO_INCREMENT,"
				+ " userid bigint not null,"
				+ "nickname varchar(40) not null,"
				+	"resourceowner bigint not null,"
				+ "portrait varchar(40) not null,"
				+ "content text not null," + "createtime datetime not null,"
				+ "ref bigint not null," 
				+"refed boolean not null,"
				+ "resource bigint not null,"
				+ "agree int not null," + "disagree int not null" + ");";
			
			//sql = "CREATE TABLE 'comment'"+contentsql;
			//jdbcTemplate.update(sql);
			
			sql = "CREATE TABLE usercomment"+contentsql;
			jdbcTemplate.update(sql);
			
			sql = "CREATE TABLE articlecomment"+contentsql;
			jdbcTemplate.update(sql);
			
			sql = "CREATE TABLE photocomment"+contentsql;
			jdbcTemplate.update(sql);
			
			sql = "CREATE TABLE spotcomment"+contentsql;
			jdbcTemplate.update(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
